﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Shop.Controllers;
using Shop.Mappers;
using Rhino.Mocks;
using Shop.Managers;

namespace TestsMyShop.Controller_Tests
{
    [TestFixture]
    public class Products
    {
        [Test]
        public void Index_should_be_called_ManagerProduct_on_All()
        {
            IWebMapper mapper = MockRepository.GenerateMock<IWebMapper>();

            IManagerProduct manager = MockRepository.GenerateMock<IManagerProduct>();
            manager.Stub(x => x.All).Return(new List<Entity.Products.Product>().AsQueryable()).IgnoreArguments().Repeat.Once();

            ProductsController controller = new ProductsController(manager, mapper);
            controller.Index();

            manager.AssertWasCalled(x => x.All);
        }

        [Test]
        public void Index_should_be_called_Webmapper_on_Wrapper()
        {
            IWebMapper mapper = MockRepository.GenerateMock<IWebMapper>();
            mapper.Stub(x => x.Wrapper(new List<Entity.Products.Product>())).IgnoreArguments().Repeat.Once();

            IManagerProduct manager = MockRepository.GenerateMock<IManagerProduct>();
            manager.Stub(x => x.All).Return(new List<Entity.Products.Product>().AsQueryable()).IgnoreArguments().Repeat.Once();

            ProductsController controller = new ProductsController(manager, mapper);
            controller.Index();

            mapper.AssertWasCalled(x => x.Wrapper(new List<Entity.Products.Product>()));
        }
    }
}
